package com.lagou.web;

import org.springframework.util.ReflectionUtils;
import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class MySpringServletInitializer implements ServletContainerInitializer {

    public void onStartup(final Set<Class<?>> set, final ServletContext servletContext) throws ServletException {
        List<WebApplicationInitializer> initializerList = new LinkedList<WebApplicationInitializer>();
        
        if(set != null){
            for (final Class<?> aClass : set) {
                if(!aClass.isInterface() && !Modifier.isAbstract(aClass.getModifiers()) && WebApplicationInitializer.class.isAssignableFrom(aClass)){
                    try {
                        initializerList.add((WebApplicationInitializer)ReflectionUtils.accessibleConstructor(aClass).newInstance());
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InstantiationException e) {
                        e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        
        if(initializerList.isEmpty()){
            
        }
    }
}
